package com.yanwq.sayhi.widget;

import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：yanweiqiang。
 * 日期：2016/6/16 0016。
 */
public abstract class TAdapter<T> extends BaseAdapter {
    public List<T> mList = new ArrayList<>();

    public TAdapter() {
        super();
    }

    public void refresh(List<T> list) {
        if (list == null) {
            return;
        }

        mList.clear();
        mList.addAll(list);
        notifyDataSetChanged();
    }

    public void load(List<T> list) {
        if (list == null) {
            return;
        }

        mList.addAll(list);
        notifyDataSetChanged();
    }

    public void update(int position, T t) {
        mList.set(position, t);
        notifyDataSetChanged();
    }

    public List<T> getList() {
        return mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public T getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
